//index.js
//获取应用实例
import {
  request
} from '../../request/index.js'
const app = getApp()

Page({
  data: {
    id: 0,
    isSelect: false,
    http: '',
    banners: [],
    result: "等待扫描",
    user: {}
  },
  onLoad: function () {
    let user = wx.getStorageSync('user');
    this.setData({
      http: app.globalData.http,
      user
    });
    this.getData();
  },

  // 获取数据
  getData() {
    request({
      url: 'Advertising/getALL',
      data: {}
    }).then(result => {
      console.log(result);
      this.setData({
        banners: result.data.data
      })
    }).then((res) => {
      setTimeout(() => {
        //隐藏loading 提示框
        wx.hideLoading();
        //隐藏导航条加载动画
        wx.hideNavigationBarLoading();
        //停止下拉刷新
        wx.stopPullDownRefresh();
      }, 1000)
    })
  },


  //扫描二维码
  scanCode() {
    if (Object.keys(this.data.user).length = !0 && this.data.user != '') {
      wx.scanCode({
        success: (result) => {
          console.log(result);
          wx.navigateTo({
            url: '../useEquipment/useEquipment?machineid=' + result.result,
          })
        },
      })
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
    }

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
  },
  //刷新
  onRefresh() {
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading();
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    wx.showLoading({
      title: '刷新中...',
    })
    this.getData();
  },

  goAdvertise(e){
    console.log(e);
    let id=e.currentTarget.dataset.id;
    request({
      url:'Advertising/getContent',
      data:{
        advertising_id:this.data.banners[id].advertising_id
      }
    }).then(r=>{
      console.log(r);
      wx.navigateTo({
        url: '../outer/outer?url='+r.data.data.advertising_jump_path,
      })
    })
  }


})